

public class SymetricTree {
    private static class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        public TreeNode(int val)
        {
            this.val = val;
        }
    }
    class Solution1 {
        public boolean isSymmetric(SymetricTree.TreeNode root) {
            if(root == null) return true;
            return compare(root.left,root.right);
        }

        private boolean compare(TreeNode left, TreeNode right)
        {
            if(left == null && right != null) return false;
            if(left != null && right == null) return false;
            if(left == null && right == null) return true;
            if(left.val != right.val) return false;
            boolean b1 = compare(left.left,right.right);
            boolean b2 = compare(left.right,right.left);
            return b1 && b2;
        }
    }
}
